package com.tt.fashionWebSite.controller;

import com.tt.fashionWebSite.dto.*;
import com.tt.fashionWebSite.service.Ad_PostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.text.ParseException;
import java.util.List;
import java.util.Map;

@Controller
public class Ad_PostController {
    @Autowired
    private Ad_PostService ad_postService;

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/header/adPost", method = RequestMethod.POST)
    public @ResponseBody
    JsonResponseDto<Integer> adminPost(HttpServletRequest request, @RequestBody BaiVietDto postDto) {
        return new JsonResponseDto<Integer>(ad_postService.adminPost(postDto));
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/ad_GetPostCategory", method = RequestMethod.GET)
    public @ResponseBody
    JsonResponseDto<List<DanhMucBaiVietDto>> getPostCategory(HttpServletRequest request) {
        return new JsonResponseDto<List<DanhMucBaiVietDto>>(ad_postService.getPostCategory(), JsonResponseCode.SUCCESS);
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/ad_GetAllPost", method = RequestMethod.GET)
    public @ResponseBody
    JsonResponseDto<List<BaiVietDto>> getAllPost(HttpServletRequest request) {
        return new JsonResponseDto<List<BaiVietDto>>(ad_postService.getAllPost(), JsonResponseCode.SUCCESS);
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/toPostPage/{maBV}", method = RequestMethod.GET)
    public @ResponseBody
    ModelAndView toPageProductSize(HttpServletRequest request, @PathVariable String maBV, Map<String, Object> map) throws ParseException {
        map.put("maBV", maBV);
        return new ModelAndView("admin/ad-post-edit");
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/editPost", method = RequestMethod.POST)
    public @ResponseBody
    JsonResponseDto<BaiVietDto> getPostInfoEdit(HttpServletRequest request, @RequestBody BaiVietDto postDto) {
        return new JsonResponseDto<BaiVietDto>(ad_postService.getPostInfoEdit(postDto), JsonResponseCode.SUCCESS);
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/registerPostEdit", method = RequestMethod.POST)
    public @ResponseBody
    JsonResponseDto<BaiVietDto> registerPostEdit(HttpServletRequest request, @RequestBody BaiVietDto postDto) {
        return new JsonResponseDto<BaiVietDto>(ad_postService.registerPostEdit(postDto), JsonResponseCode.SUCCESS);
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/getAllPostCategory", method = RequestMethod.GET)
    public @ResponseBody
    JsonResponseDto<List<DanhMucBaiVietDto>> getAllCategory(HttpServletRequest request) {
        return new JsonResponseDto<List<DanhMucBaiVietDto>>(ad_postService.getAllCategory(), JsonResponseCode.SUCCESS);
    }

}
